/***********************************************用户提醒*************************************************** */
//成功或失败总提醒
let told = document.getElementById('told');
let toTold = document.getElementById('toTold');

function close() {
    told.style.display = 'none';
};

function open() {
    told.style.display = 'block';
};
document.getElementById('toldClose').addEventListener('click', function() {
        told.style.display = 'none';
    })
    /**********************************************我的主页布局********************************************* */
function toFix() {
    let left = document.querySelector('.left');
    document.addEventListener('scroll', function() {
        if (window.pageYOffset >= 334) {
            left.style.position = 'fixed';
            left.style.left = '5rem';
        } else {
            left.style.position = 'absolute';
            left.style.left = '0';
        }
    })
}
toFix();

//*******************************************************显示用户信息********************************************/
function info() {
    // let a = document.getElementById('a');
    let b = document.getElementById('b');
    let c = document.getElementById('c');
    let d = document.getElementById('d');
    let e = document.getElementById('e');

    b.innerHTML = '用户名：' + localStorage.getItem('username');
    c.innerHTML = '用户id：' + localStorage.getItem('id');
    d.innerHTML = '真实姓名：' + localStorage.getItem('username');
    e.innerHTML = '电话号码：' + localStorage.getItem('phone');
}
info();
//*******************************************上传头像********************************************************************* */
document.getElementById("myimg").src = 'http://www.rushmc.top/' + localStorage.getItem('url');
document.getElementById("headImg").src = 'http://www.rushmc.top/' + localStorage.getItem('url');
document.getElementById("headname").innerHTML = localStorage.getItem('username');
document.getElementById("myfile").onchange = function() {
    let input = document.getElementById("myfile");
    let mydata = new FormData();
    mydata.append("id", localStorage.getItem('id'));
    mydata.append('avatar', input.files[0]);
    $.ajax({
        url: 'http://www.rushmc.top/api/updateAvatar',
        type: 'POST',
        data: mydata,
        cache: false,
        processData: false,
        contentType: false,
        success: function(res) {
            console.log(res);
            localStorage.url = res.data;
            let a = 'http://www.rushmc.top/' + localStorage.getItem('url');
            console.log(a);
            // $("#myimg").src = a;
            document.getElementById('myimg').src = a;
            toTold.innerHTML = '头像上传成功';
            toTold.style.color = 'green';
            open();
            setTimeout('close()', 3000);
        },
        error: function(res) {
            console.log(res);
            toTold.innerHTML = '头像上传失败';
            toTold.style.color = 'red';
            open();
            setTimeout('close()', 3000);
        }
    });
    let pic = input.files[0];
    let read = new FileReader();
    read.onload = function() {
        document.getElementById("myimg").src = 'http://www.rushmc.top/' + localStorage.getItem('url');
    };
    read.readAsDataURL(pic);
};
//*************************************************发动态*************************************************************** */
function upload() {
    var fileurl = document.getElementById("laFile").value;
    // 这时的fileurl不是 laFile 框中的值
    return fileurl;
}
document.getElementById('all').addEventListener('click', function() {
    document.getElementById("show").style.display = "none";
    let pObj = show.childNodes;
    for (let i = pObj.length - 1; i >= 0; i--) {
        show.removeChild(pObj[i]);
    }
})
let formdata = new FormData();
let imgFiles = document.getElementById("laFile");
let urlArr = [];
document.getElementById("laFile").onchange = function() {
    for (let i = 0; i < imgFiles.files.length; i++) {
        formdata.append("files", imgFiles.files[i]);
        let laPic = new Image;
        laPic.src = window.URL.createObjectURL(imgFiles.files[i]);
        console.log(laPic.src);
        laPic.title = imgFiles.files[i].name;
        document.getElementById('lookImg').appendChild(laPic);
        laPic.addEventListener('click', function() {
            document.getElementById('showPic').style.display = 'block';
            document.getElementById('showPic').src = laPic.src;
            document.getElementById('showPic').addEventListener('click', function() {
                document.getElementById('showPic').style.display = 'none';
                document.getElementById('showPic').src = '';
            })
        })
        laPic.style.marginRight = '0.5rem';
        laPic.style.width = '100px';
        laPic.style.height = '120px';
        urlArr.push(upload());
        window.URL.revokeObjectURL(imgFiles.files[i]);
    }
};
document.getElementById("sub").onclick = function() {
    formdata.append('userId', localStorage.getItem('id'));
    let laText = document.getElementById("laText").value;
    let laTitle = document.getElementById("laTitle").value;
    formdata.append('content', laText);
    formdata.append('title', laTitle);
    if (document.getElementById("laFile").files.length) {
        formdata.append('hasPicture', 1);
    } else {
        console.log("number = 0");
        formdata.append('hasPicture', 0);
    }
    $.ajax({
        url: 'http://www.rushmc.top/api/dynamicState/insert',
        type: 'POST',
        data: formdata,
        cache: false,
        processData: false,
        contentType: false,
        success: function(res) {
            console.log(res);
            toTold.innerHTML = '动态发表成功';
            toTold.style.color = 'green';
            open();
            setTimeout('close()', 3000);
            for (let i = 0; i < imgFiles.files.length; i++) {
                let newImg = document.createElement('img');
                newImg.id = "img" + i;
                document.getElementById("lookImg").appendChild(newImg);
                newImg.url = 'http://www.rushmc.top/' + res.data.urls[i];
            }

        },
        error: function(res) {
            console.log(res);
            toTold.innerHTML = '动态发表失败';
            toTold.style.color = 'red';
            open();
            setTimeout('close()', 3000);
        }
    });
};
//动态草稿箱
document.getElementById('keep').addEventListener('click', function() {
    document.getElementById('showPic').style.display = 'none';

    let laText = document.getElementById("laText").value;
    let laTitle = document.getElementById("laTitle").value;
    sessionStorage.keepText = laText;
    sessionStorage.keepTitle = laTitle;
    sessionStorage.urlArr = urlArr;
    document.querySelector('.keepTitle').value = sessionStorage.getItem('keepTitle');
    document.querySelector(".keepText").value = sessionStorage.getItem('keepText');
    if (sessionStorage.getItem('urlArr') != null) {
        for (let i = 0; i < sessionStorage.getItem('urlArr').length; i++) {
            let img = document.createElement('img');
            document.getElementById('lookImg').appendChild(img);
            img.src = urlArr[i];
            img.style.height = '10rem';
        }
    }
})
document.getElementById('myDraft').addEventListener('click', function() {
        document.querySelector('.keepTitle').value = sessionStorage.getItem('keepTitle');
        document.querySelector(".keepText").value = sessionStorage.getItem('keepText');
        if (urlArr != null) {
            for (let i = 0; i < urlArr.length; i++) {
                let img = document.createElement('img');
                document.getElementById('lookImg').appendChild(img);
                img.src = urlArr[i];
                img.style.height = '10rem';
            }
        }
    })
    //**********************************************显示我的动态(id)******************************************* */
    //格式化日期
function getTime(time) {
    var b = time.substr(0, 10);
    var c = time.substr(11, 8);
    return b + ' ' + c;
}
window.onload = function() {
        let insearch = localStorage.getItem('id').toString();
        $.ajax({
            url: 'http://www.rushmc.top/api/dynamicState/select/' + insearch,
            type: 'get',
            data: { userId: insearch },
            success: function(res) {
                console.log(res);
                let ul = document.getElementById("ul");
                for (let i = 0; i < res.data.length; i++) {
                    let li = document.createElement('li');
                    ul.appendChild(li);
                    li.setAttribute("id", res.data[i]['id']);
                    //显示我的动态详情
                    li.addEventListener('click', function() {
                        localStorage.showId = res.data[i]['id'];
                        document.getElementById('show').style.display = 'block';
                        $.ajax({
                            url: 'http://www.rushmc.top/api/dynamicState/search/' + res.data[i]['id'],
                            type: 'get',
                            data: { key: res.data[i]['id'] },
                            success: function(res) {
                                console.log(res);
                                let show = document.getElementById('show');
                                let showPic = document.getElementById('showPic');
                                for (let i = 0; i < res.data.length; i++) {
                                    let h2 = document.createElement('h2');
                                    show.appendChild(h2);
                                    h2.innerHTML = res.data[i]['title'];
                                    let div1 = document.createElement('div');
                                    show.appendChild(div1);
                                    let span1 = document.createElement('span');
                                    div1.appendChild(span1);
                                    span1.innerHTML = 'id : ' + res.data[i]['id'];
                                    let span2 = document.createElement('span');
                                    div1.appendChild(span2);
                                    span2.innerHTML = 'userId : ' + res.data[i]['userId'];
                                    let span3 = document.createElement('span');
                                    div1.appendChild(span3);
                                    span3.innerHTML = 'username : ' + res.data[i]['username'];
                                    let span4 = document.createElement('span');
                                    div1.appendChild(span4);
                                    span4.innerHTML = 'creationTime : ' + getTime(res.data[i]['creationTime']);
                                    let div = document.createElement('div');
                                    show.appendChild(div);
                                    div.setAttribute('class', 'detailConent');
                                    div.innerHTML = res.data[i]['content'];
                                    document.getElementById("reveal").style.display = "none";
                                    for (let j = 0; j < res.data[i]['urls'].length; j++) {
                                        let img = document.createElement('img');
                                        show.appendChild(img);
                                        img.src = 'http://www.rushmc.top/' + res.data[i]['urls'][j];
                                        img.style.marginRight = '0.5rem';
                                        img.addEventListener('click', function() {
                                            show.style.display = 'none';
                                            showPic.style.display = 'block';
                                            showPic.src = img.src;
                                        })
                                        showPic.addEventListener('click', function() {
                                            show.style.display = 'block';
                                            showPic.style.display = 'none';
                                            showPic.src = '';
                                        })
                                    }
                                    let btnBox = document.createElement('div');
                                    document.getElementById("show").appendChild(btnBox);
                                    btnBox.setAttribute('class', 'btnBox');
                                    let btn = document.createElement('button');
                                    btnBox.appendChild(btn);
                                    btn.innerHTML = "返回";
                                    btn.addEventListener('click', function() {
                                        document.getElementById("reveal").style.display = "block";
                                        document.getElementById("show").style.display = "none";
                                        let pObj = show.childNodes;
                                        for (let i = pObj.length - 1; i >= 0; i--) {
                                            show.removeChild(pObj[i]);
                                        }
                                    })
                                    let del = document.createElement('button');
                                    btnBox.appendChild(del);
                                    del.innerHTML = "删除";
                                    del.addEventListener('click', function() {
                                        $.ajax({
                                            url: 'http://www.rushmc.top/api/dynamicState/delete',
                                            type: 'post',
                                            data: { id: res.data[i]['id'] },
                                            success: function(res) {
                                                console.log(res);
                                                document.getElementById('show').style.display = 'none';
                                                document.getElementById("reveal").style.display = "block";
                                            },
                                            error: function(res) {
                                                console.log(res);
                                            }
                                        })
                                    })
                                }
                            },
                            error: function(res) {
                                console.log(res);
                            }
                        });
                    });
                    if (localStorage.getItem('id') == res.data[i]['userId']) {
                        let h2 = document.createElement('h2');
                        li.appendChild(h2);
                        h2.innerHTML = res.data[i]['title'];
                        let div1 = document.createElement('div');
                        li.appendChild(div1);
                        div1.setAttribute('class', 'div1');
                        let span1 = document.createElement('span');
                        div1.appendChild(span1);
                        span1.innerHTML = 'id : ' + res.data[i]['id'];
                        let span2 = document.createElement('span');
                        div1.appendChild(span2);
                        span2.innerHTML = 'userId : ' + res.data[i]['userId'];
                        let span3 = document.createElement('span');
                        div1.appendChild(span3);
                        span3.innerHTML = 'username : ' + res.data[i]['username'];
                        let span4 = document.createElement('span');
                        div1.appendChild(span4);
                        span4.innerHTML = 'creationTime : ' + getTime(res.data[i]['creationTime']);
                        let div = document.createElement('div');
                        li.appendChild(div);
                        div.innerHTML = res.data[i]['content'];
                        // *************************************************************************************************
                        // let liList = document.getElementsByTagName('li');
                        // [].forEach.call(liList, (li, index) => {
                        //     li.addEventListener('click', getData.bind(li, index))
                        // })

                        // function getData(index) {
                        //     console.log(index, this);
                        //     alert(this.id);
                        // }
                    }

                }

            },
            error: function(res) {
                console.log(res);
                let li = document.createElement('li');
                ul.appendChild(li);
                li.innerHTML = "暂无动态";
            }
        });

    }
    /*****************************************************搜索动态******************************************************** */
document.getElementById("search").onclick = function() {
        document.getElementById('showSearch').style.display = 'block';
        let insec = document.getElementById("insec");
        let insearch = insec.value.toString();
        $.ajax({
            url: 'http://www.rushmc.top/api/dynamicState/search/' + insearch,
            type: 'get',
            data: { key: insec.value },
            success: function(res) {
                console.log(res);
                let showUl = document.getElementById("showUl");
                let pObj1 = showUl.childNodes;
                for (let i = pObj1.length - 1; i >= 0; i--) {
                    showUl.removeChild(pObj1[i]);
                }
                for (let i = 0; i < res.data.length; i++) {
                    let li = document.createElement('li');
                    showUl.appendChild(li);
                    li.setAttribute("id", res.data[i]['id']);
                    //显示用户动态详情
                    li.addEventListener('click', function() {
                        localStorage.showUserId = res.data[i]['id'];
                        document.getElementById('show').style.display = 'block';
                        document.getElementById("showSearch").style.display = "none";
                        $.ajax({
                            url: 'http://www.rushmc.top/api/dynamicState/search/' + res.data[i]['id'],
                            type: 'get',
                            data: { key: res.data[i]['id'] },
                            success: function(res) {
                                console.log(res);
                                let show = document.getElementById('show');
                                for (let i = 0; i < res.data.length; i++) {
                                    let h2 = document.createElement('h2');
                                    show.appendChild(h2);
                                    h2.innerHTML = res.data[i]['title'];
                                    let div1 = document.createElement('div');
                                    show.appendChild(div1);
                                    let span1 = document.createElement('span');
                                    div1.appendChild(span1);
                                    span1.innerHTML = 'id : ' + res.data[i]['id'];
                                    let span2 = document.createElement('span');
                                    div1.appendChild(span2);
                                    span2.innerHTML = 'userId : ' + res.data[i]['userId'];
                                    let span3 = document.createElement('span');
                                    div1.appendChild(span3);
                                    span3.innerHTML = 'username : ' + res.data[i]['username'];
                                    let span4 = document.createElement('span');
                                    div1.appendChild(span4);
                                    span4.innerHTML = 'creationTime : ' + getTime(res.data[i]['creationTime']);
                                    let div = document.createElement('div');
                                    show.appendChild(div);
                                    div.setAttribute('class', 'secConent');
                                    div.innerHTML = res.data[i]['content'];
                                    for (let j = 0; j < res.data[i]['urls'].length; j++) {
                                        let img = document.createElement('img');
                                        show.appendChild(img);
                                        img.src = 'http://www.rushmc.top/' + res.data[i]['urls'][j];
                                        img.style.height = '200px';
                                        img.addEventListener('click', function() {
                                            show.style.display = 'none';
                                            showPic.style.display = 'block';
                                            showPic.src = img.src;
                                        })
                                        showPic.addEventListener('click', function() {
                                            show.style.display = 'block';
                                            showPic.style.display = 'none';
                                            showPic.src = '';
                                        })
                                    }
                                    let btnBox = document.createElement('div');
                                    document.getElementById("show").appendChild(btnBox);
                                    btnBox.setAttribute('class', 'btnBox');
                                    let btn = document.createElement('button');
                                    btnBox.appendChild(btn);
                                    btn.innerHTML = "返回";
                                    btn.addEventListener('click', function() {
                                        document.getElementById("showSearch").style.display = "block";
                                        document.getElementById("show").style.display = "none";
                                        let pObj = show.childNodes;
                                        for (let i = pObj.length - 1; i >= 0; i--) {
                                            show.removeChild(pObj[i]);
                                        }

                                    })
                                    let del = document.createElement('button');
                                    btnBox.appendChild(del);
                                    del.innerHTML = "删除";
                                    del.addEventListener('click', function() {
                                        $.ajax({
                                            url: 'http://www.rushmc.top/api/dynamicState/delete',
                                            type: 'post',
                                            data: { id: res.data[i]['id'] },
                                            success: function(res) {
                                                console.log(res);
                                                document.getElementById('show').style.display = 'none';
                                                document.getElementById("showSearch").style.display = "block";
                                                toTold.innerHTML = '删除成功';
                                                toTold.style.color = 'green';
                                                open();
                                                setTimeout('close()', 3000);
                                            },
                                            error: function(res) {
                                                console.log(res);
                                                toTold.innerHTML = '删除失败';
                                                toTold.style.color = 'red';
                                                open();
                                                setTimeout('close()', 3000);
                                            }
                                        })
                                    })
                                }

                            },
                            error: function(res) {
                                console.log(res);
                            }
                        });
                    });
                    let h2 = document.createElement('h2');
                    li.appendChild(h2);
                    h2.innerHTML = res.data[i]['title'];
                    let div1 = document.createElement('div');
                    li.appendChild(div1);
                    div1.setAttribute('class', 'div1');
                    let span1 = document.createElement('span');
                    div1.appendChild(span1);
                    span1.innerHTML = 'id : ' + res.data[i]['id'];
                    let span2 = document.createElement('span');
                    div1.appendChild(span2);
                    span2.innerHTML = 'userId : ' + res.data[i]['userId'];
                    let span3 = document.createElement('span');
                    div1.appendChild(span3);
                    span3.innerHTML = 'username : ' + res.data[i]['username'];
                    let span4 = document.createElement('span');
                    div1.appendChild(span4);
                    span4.innerHTML = 'creationTime : ' + getTime(res.data[i]['creationTime']);
                    let div = document.createElement('div');
                    li.appendChild(div);
                    div.innerHTML = res.data[i]['content'];
                }
            },
            error: function(res) {
                console.log(res);
            }
        });
    }
    /******************************************************** 个人相册************************************************** */
    //新建相册
document.getElementById('addAl').addEventListener('click', function() {
        let tit = document.getElementById('addTit').value;
        if (tit == 0 || tit == null) {
            toTold.innerHTML = '标题不能为空';
            toTold.style.color = 'red';
            open();
            setTimeout('close()', 3000);
        } else {
            let alData = new FormData();
            alData.append('title', tit);
            alData.append('userId', localStorage.getItem('id'))
            $.ajax({
                url: 'http://www.rushmc.top/api/createAlbum',
                type: 'post',
                data: alData,
                processData: false,
                contentType: false,
                success: function(res) {
                    console.log(res);
                    toTold.innerHTML = '新建相册成功';
                    toTold.style.color = 'green';
                    open();
                    setTimeout('close()', 3000);
                },
                error: function(res) {
                    console.log(res);
                    toTold.innerHTML = '新建相册失败';
                    toTold.style.color = 'red';
                    open();
                    setTimeout('close()', 3000);
                }
            })
        }
    })
    //我的相册
document.getElementById('myPic').addEventListener('click', function() {
    let prompt = document.getElementById('prompt');
    prompt.style.display = 'none';
    let id = localStorage.getItem('id');
    let AlDetails_Bd = document.getElementById('AlDetails_Bd');
    let AlDetails = document.getElementById('AlDetails');
    let album = document.getElementById('album');
    let addBox = document.getElementById('addBox');
    let addBoxObj = addBox.childNodes;
    let AlImgAdd = document.getElementById('AlImgAdd');
    for (let i = addBoxObj.length - 1; i >= 0; i--) {
        addBox.removeChild(addBoxObj[i]);
    }

    //根据id查找用户相册，显示出相册信息
    $.ajax({
        url: 'http://www.rushmc.top/api/album/oneAlbum',
        type: 'get',
        data: {
            userId: id
        },
        success: function(res) {
            console.log(res);
            for (let i = 0; i < res.data.length; i++) {
                let addimg;
                if (res.data[i].title != 0) {
                    let nameArr = [];
                    let Al_back = document.getElementById('Al_back');
                    let Al_look = document.getElementById('Al_look');
                    let Al_del = document.getElementById('Al_del');
                    let bigSpan = document.createElement('div');
                    addBox.appendChild(bigSpan);
                    let h4 = document.createElement('h4');
                    bigSpan.appendChild(h4);
                    h4.innerHTML = res.data[i].title;
                    let newAl = document.createElement('img');
                    bigSpan.appendChild(newAl);
                    if (res.data[i].pictureList) {
                        newAl.src = 'http://www.rushmc.top/' + res.data[i].pictureList[0].url;
                    }
                    //为每个相册添加监听事件
                    newAl.addEventListener('click', function() {
                        let AlData = new FormData();
                        AlDetails.style.display = 'block';
                        album.style.display = 'none';
                        prompt.style.display = 'none';

                        //上传照片到个人相册
                        AlImgAdd.addEventListener('change', function() {
                            let addData = new FormData();
                            for (let i = 0; i < AlImgAdd.files.length; i++) {
                                addData.append("file", AlImgAdd.files[i]);
                                let addImg = document.createElement('img');
                                document.getElementById("AlDetails_Bd").appendChild(addImg);
                            }
                            addData.append('albumId', res.data[i]['albumId']);
                            $.ajax({
                                url: 'http://www.rushmc.top/api/upload',
                                data: addData,
                                type: 'post',
                                cache: false,
                                processData: false,
                                contentType: false,
                                success: function(result) {
                                    console.log(result);
                                    console.log(AlImgAdd.files.length);
                                    for (let i = 0; i < AlImgAdd.files.length; i++) {
                                        let addImg = document.createElement('img');
                                        document.getElementById("AlDetails_Bd").appendChild(addImg);
                                        addImg.src = 'http://www.rushmc.top/' + result.data;
                                        addImg.id = AlImgAdd.files[i].name;
                                        addImg.setAttribute('class', AlImgAdd.files[i].name);
                                        nameArr.push(AlImgAdd.files[i].name);
                                    }
                                    toTold.innerHTML = '图片上传成功';
                                    toTold.style.color = 'green';
                                    open();
                                    setTimeout('close()', 3000);

                                },
                                error: function(result) {
                                    console.log(result);
                                    toTold.innerHTML = '图片上传失败';
                                    toTold.style.color = 'red';
                                    open();
                                    setTimeout('close()', 3000);
                                }
                            })

                        })

                        if (res.data[i].pictureList != null) {
                            //显示出不同相册的所有照片
                            for (let k = 0; k < res.data[i].pictureList.length; k++) {
                                addimg = document.createElement('img');
                                AlDetails_Bd.appendChild(addimg);
                                addimg.src = 'http://www.rushmc.top/' + res.data[i].pictureList[k].url;
                                addimg.style.height = '250px';
                                addimg.style.marginRight = '0.5rem';

                                //为每张照片添加点击事件
                                addimg.addEventListener('click', function() {
                                    prompt.style.display = 'block';
                                    Al_look.addEventListener('click', function() {
                                        showPic.style.display = 'block';
                                        showPic.src = addimg.src;
                                    })
                                })
                                showPic.addEventListener('click', function() {
                                        showPic.style.display = 'none';
                                        showPic.src = '';
                                    })
                                    //监听返回按钮
                                Al_back.addEventListener('click', function() {
                                        prompt.style.display = 'none';
                                    })
                                    //监听删除按钮
                                Al_del.addEventListener('click', function() {
                                    console.log("执行监听")
                                    AlData.append('filename', nameArr[k]);
                                    AlData.append('albumId', res.data[i].albumId);
                                    $.ajax({
                                        url: 'http://www.rushmc.top/api/deletePic',
                                        type: 'post',
                                        data: AlData,
                                        cache: false,
                                        processData: false,
                                        contentType: false,
                                        success: function(res) {
                                            toTold.innerHTML = res.msg;
                                            toTold.style.color = 'green';
                                            open();
                                            setTimeout('close()', 3000);
                                            console.log(res);
                                        },
                                        error: function(res) {
                                            toTold.innerHTML = res.msg;
                                            toTold.style.color = 'red';
                                            open();
                                            setTimeout('close()', 3000);
                                        }
                                    })
                                })
                            }
                        }
                        let Albtn = document.createElement('button');
                        AlDetails.appendChild(Albtn);
                        Albtn.innerHTML = "返回";
                        Albtn.addEventListener('click', function() {
                            AlDetails.style.display = 'none';
                            album.style.display = 'block';
                            prompt.style.display = 'none';
                            AlDetails.removeChild(Albtn);
                            let pObj = AlDetails_Bd.childNodes;
                            for (let i = pObj.length - 1; i >= 0; i--) {
                                AlDetails_Bd.removeChild(pObj[i]);
                            }
                        })


                        //图片懒加载

                        let imgs = document.querySelectorAll('img');

                        function lazyload() {
                            //可视区域高度
                            let h = document.documentElement.clientHeight;
                            //滚动区域高度
                            let s = document.documentElement.scrollTop || document.body.scrollTop;
                            for (let a = 0; a < imgs.length; a++) {
                                //图片距离顶部的距离大于可视区域和滚动区域之和时懒加载
                                if ((h + s) > imgs[a].offsetTop) {
                                    (function(i) {
                                        setTimeout(function() {
                                            if (res.data[i].pictureList != null) {
                                                for (let k = 0; k < res.data[i].pictureList.length; k++) {
                                                    let temp = new Image();
                                                    temp.src = 'http://www.rushmc.top/' + res.data[i].pictureList[k].url;
                                                    temp.onload = function() {
                                                        imgs.src = temp.src;
                                                    }
                                                }
                                            }
                                        }, 2000)
                                    })(i)
                                }
                            }
                        }
                        lazyload();
                    })
                }
            }
        }
    })
})